<?php
if(!$login_do) include("config.php");
if($_POST['session_id']){
	//////////////////////////////////////////////////////////////////////////////////////
	//获取姓名学号
	$snoopy1 = new Snoopy;
	//模拟HEADER
	$snoopy1->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
	//获取分析表单
	$snoopy1->fetch($personurl);
	$res1 = $snoopy1->results;

	//超时返回
	if ($snoopy1->status != '200' || $snoopy1->timed_out) {
    	echo json_err(1,"页面获取超时！");
    	return;
	}
	$snoopy_results = $snoopy1->results;

	$res1_html = new simple_html_dom();
	$res1_html->load($res1);
	$res1_tds  = $res1_html->find('td');
	$info_data = [];
	$info_title= [];
	foreach ($res1_tds as $key => $value){
		$innertext = trim(strip_tags($value->innertext));
		if($key == 0 || ($key>4 && $key%2==1)){
			$info_title[] = $innertext;
		}
		if($key == 1 || ($key>4 && $key%2==0)){
			$info_data[] = $innertext;
		}
	}
	$info = ["title"=>$info_title,"data"=>$info_data];

	$xh = $info_data[0];
	$xm = $info_data[1];
	$ds = $info_data[63];

	$yx = $info_data[59];
	$yx_arr = explode("_", $yx);
	$bj = $yx_arr[1].substr($xh,1,2)."研";
	$res1_html->clear();

	$table['ct_info'] = array(
		'xm'=>$xm,
		'xh'=>$xh,
		'ds'=>$ds,
		'bj'=>$bj
	);

	file_put_contents("info/".$_SESSION["userID"], $snoopy_results);

	//////////////////////////////////////////////////////////////////////////////////////
	//获取照片
	$snoopy2 = new Snoopy;
	//模拟HEADER
	$snoopy2->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
	//获取分析表单
	$snoopy2->fetch($photourl);
	$res2 = $snoopy2->results;

	//超时返回
	if ($snoopy2->status != '200' || $snoopy2->timed_out) {
    	echo json_err(1,"页面获取超时！");
    	return;
	}
	//$pic_data = "data:image/gif;base64,".base64_encode($snoopy2->results);
	file_put_contents("photo/".$_SESSION["userID"].".gif", $snoopy2->results);

	//////////////////////////////////////////////////////////////////////////////////////
	//noapi调用
	if(!empty($_POST['noapi'])){
		//echo "姓名：".$xm."    学号：".$xh;
		echo json_encode($info);
		return;
	}
	if(empty($login_do)) echo json_encode($info);
	else echo json_encode($table['ct_info']);
	return;

}else{
	echo json_err(2,'提交数据不全!');
	return;
}
?>